﻿#if UNITY_EDITOR
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
/// <summary>
/// 解析XLSX表架构
/// </summary>
partial class EditorWindowResolverXlsxSchema : AbsESF_EditorWindow
{
    protected override AbsESF_EditorBuildAsset config => ESF_Logic.xlsxAutoBuildFolder;

    /// <summary>
    /// OnGUI
    /// </summary>
    protected override void OnRunGUI()
    {
        if (GUILayout.Button($"{ESF_enGUIDisplayWord.Resolver.ESF_ToAlias()} 所有Xlsx表架构"))
        {
            ESF_Logic.ResolveAllXlsxSchema();
        }
        if (GUILayout.Button($"{ESF_enGUIDisplayWord.Build.ESF_ToAlias()} 所有Xlsx表脚本"))
        {
            ESF_Logic.BuildAllXlsxScript();
        }
        if (GUILayout.Button($"{ESF_enGUIDisplayWord.Build.ESF_ToAlias()} 所有Xlsx表数据库"))
        {
            ESF_Logic.BuildAllXlsxDbMaster();
        }
        if (GUILayout.Button($"所有Xlsx表 {ESF_enGUIDisplayWord.OneKeyBuild.ESF_ToAlias()} "))
        {
            ESF_Logic.OneKeyBuildAllXlsx();
        }
        ESF_Utility.DrawSeparator();
        if (GUILayout.Button(ESF_enGUIDisplayWord.Save.ESF_ToAlias()))
        {
            OnSaveConfig();
        }
        if (GUILayout.Button(ESF_enGUIDisplayWord.Load.ESF_ToAlias()))
        {
            mNodes = ESF_Logic.CollectXlsxSchema<ESF_CollectAsset_XLSX>();            
            ESF_Utility.ExecuteMenuAssetsRefresh();
        }
    }

    /// <summary>
    /// 节点组
    /// </summary>   
    List<ESF_CollectAsset_XLSX> mNodes = null;
    /// <summary>
    /// 滚动视图位置
    /// </summary>
    Vector2 mScrollView = Vector2.zero;
    /// <summary>
    /// 绘制表格
    /// </summary>
    protected override void OnDrawBottomUnityGUI()
    {
        OnDrawXlsx();
    }

    private void OnDrawXlsx()
    {
        mScrollView = EditorGUILayout.BeginScrollView(mScrollView);
        ESF_Utility.DrawCollect(mNodes, (node, idx, number) =>
        {
            GUILayout.Label($"XlsxDbTable索引：{node.xlsxScriptBuildSettingConfig.xml.tableIndex}");
            ESF_Utility.EnumPopup(node.xlsxTableSchemaXmlConfig.xml.xlsxTableClassify, true);
            if (GUILayout.Button($"{ESF_enGUIDisplayWord.Setting.ESF_ToAlias()}【{number}】"))
            {
                EditorWindowSFXLSXConfigSetting win = GetWindow<EditorWindowSFXLSXConfigSetting>();
                win.SetData(node);
                win.Show();
            }
            if (GUILayout.Button($"{ESF_enGUIDisplayWord.Query.ESF_ToAlias()}{ESF_enGUIDisplayWord.Data.ESF_ToAlias()}【{number}】"))
            {
                EditorWindowSFXLSXConfigQueryData query = GetWindow<EditorWindowSFXLSXConfigQueryData>();
                query.SetData(node);
                query.Show();
            }
            if (GUILayout.Button($"{ESF_enGUIDisplayWord.Config.ESF_ToAlias()}【{number}】"))
            {
                ESF_Utility.PingObject(node.xlsxTableSchemaXmlConfig.filePath);
            }
            if (GUILayout.Button($"{ESF_enGUIDisplayWord.Resolver.ESF_ToAlias()} Xlsx表架构【{number}】"))
            {
                ESF_Logic.ResolveXlsxSchema(node);
                ESF_Utility.ExecuteMenuAssetsRefresh();
            }
            if (GUILayout.Button($"{ESF_enGUIDisplayWord.Build.ESF_ToAlias()} Xlsx表脚本【{number}】"))
            {
                ESF_Logic.BuildXlsxScript(node);
                ESF_Utility.ExecuteMenuAssetsRefresh();
            }
            if (GUILayout.Button($"{ESF_enGUIDisplayWord.Build.ESF_ToAlias()} Xlsx表数据库【{number}】"))
            {
                ESF_Logic.BuildXlsxDbMaster(node);
                ESF_Utility.ExecuteMenuAssetsRefresh();
            }
        });
        EditorGUILayout.EndScrollView();
    }
}
#endif
